<?php
class mastersuppliercontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('mastersupplier_model');
		$this->load->library('session');
		$this->load->library('pagination_editable');
		if(($this->session->userdata('fullname') == '') || ($this->session->userdata('fullname') == NULL)){
			redirect('logincontroller');
		}
	}
	
	function index()
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mastersuppliercontroller/index');
		$config['total_rows'] = $this->mastersupplier_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		         
		if (isset($_POST['btnview'])) 
		{
			if($_POST['kdsuppview'] == "0")
			{         
				$dataprofile = array(
					'page_title' => 'Master > Supplier',
					'name' => $this->session->userdata('fullname'),
					'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
					'mastersupp' => $this->mastersupplier_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdsuppview'] == "1")
			{
				$this->mastersupplier_model->setKodeSupplier($_POST['suppview']);
				$dataprofile = array(
					'page_title' => 'Master > Supplier',
					'name' => $this->session->userdata('fullname'),
					'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
					'mastersupp' => $this->mastersupplier_model->getkdsupplike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdsuppview'] == "2")
			{
				$this->mastersupplier_model->setSuppliername($_POST['suppview']);
				$dataprofile = array(
					'page_title' => 'Master > Supplier',
					'name' => $this->session->userdata('fullname'),
					'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
					'mastersupp' => $this->mastersupplier_model->getnamasupplike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdsuppview'] == "3")
			{
				$this->mastersupplier_model->setWebsitename($_POST['suppview']);
				$dataprofile = array(
					'page_title' => 'Master > Supplier',
					'name' => $this->session->userdata('fullname'),
					'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
					'mastersupp' => $this->mastersupplier_model->getwebsitelike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
		}
		else
		{
			$dataprofile = array(
				'page_title' => 'Master > Supplier',
				'name' => $this->session->userdata('fullname'),
				'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
				'mastersupp' => $this->mastersupplier_model->getListlimit($config['per_page'],$page),
				'links' => $this->pagination_editable->create_links(),
				'message' => ''		
			);		

		}      
				
		$content = array(
			'content' => 'master/supplier/view'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
	
    function getmastersupplier() 
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mastersuppliercontroller/index');
		$config['total_rows'] = $this->mastersupplier_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		$kdsupp = $this->uri->segment(3);
		$this->mastersupplier_model->setKodeBank($kdsupp);
        $dataprofile = array(
            'page_title' => 'Master > Supplier',
            'name' => $this->session->userdata('fullname'),
			'mastersupp' => $this->mastersupplier_model->getListlimit($config['per_page'],$page),
			'links' => $this->pagination_editable->create_links(),
			'message' => ''
            /*'individulist' => $this->Individu_model->getOneSelect(),
            'wilayahlist' => $this->Wilayah_model->getWilayahList(),
            'status_nikah' => $this->Statusnikah_model->getStatusNikahList(),
            'foto' => $this->Individu_model->get_images(),
            'role' => $this->session->userdata('role')*/
        );
        $content = array(
            'content' => 'master/supplier/view'
        );
        $this->template->load('templates/default', $content, $dataprofile);
    }
	
	function tambahmastersupplier() 
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('mastersuppliercontroller/index');
		$config['total_rows'] = $this->mastersupplier_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
        if (isset($_POST['btnSave'])) 
		{
			if (isset($_POST['nmsupp']) &&
					isset($_POST['contact']) &&
                    isset($_POST['email']) &&
					isset($_POST['notlp']) &&
                    !($_POST['nmsupp'] == '') &&
                    !($_POST['contact'] == '') &&
					!($_POST['email'] == '') &&
                    !($_POST['notlp'] == '')) 
			 {
	            
				$this->mastersupplier_model->setKodeSupplier($_POST['kdsupp']);
				$this->mastersupplier_model->setSuppliername($_POST['nmsupp']);
                $this->mastersupplier_model->setAddress($_POST['alamat']);
                $this->mastersupplier_model->setNoTlp($_POST['notlp']);
                $this->mastersupplier_model->setEmail($_POST['email']);
				$this->mastersupplier_model->setNoHp($_POST['nohp']);
                $this->mastersupplier_model->setWebsitename($_POST['nmaweb']);
				$this->mastersupplier_model->setContactPerson($_POST['contact']);
                $this->mastersupplier_model->setCreatedBy($this->session->userdata('userid'));
			   	$tanggal=date('Y-m-d H:i:s', strtotime('now'));
				$this->mastersupplier_model->setCreatedOn($tanggal);
				$this->mastersupplier_model->setLastupdateby($this->session->userdata('userid'));
				$this->mastersupplier_model->setLastupdateon($tanggal);
				
				$this->mastersupplier_model->insert();
				
                redirect('mastersuppliercontroller');
            } else {
                $dataprofile = array(
					'page_title' => 'Master > Supplier',
            		'name' => $this->session->userdata('fullname'),
					'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
					'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Master Supplier </div>',
					'mastersupp' => $this->mastersupplier_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links()
                    
					/*'page_title' => 'Tambah Data Individu',
                    'name' => $this->session->userdata('name'),
                    'role' => $this->session->userdata('role'),
                    'wilayahlist' => $this->Wilayah_model->getWilayahList(),
                    'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Individu Jema\'at</div>',
                    'status_nikah' => $this->Statusnikah_model->getStatusNikahList()*/
                );
                $content = array(
                    'content' => 'master/supplier/view'
                );
                $this->template->load('templates/default', $content, $dataprofile);
            }
        } else {
           $dataprofile = array(
			'page_title' => 'Master > Supplier',
			'name' => $this->session->userdata('fullname'),
			'SupplierCode' => $this->mastersupplier_model->getSupplierCode(),
			'mastersupp' => $this->mastersupplier_model->getListlimit($config['per_page'],$page),
			'links' => $this->pagination_editable->create_links(),			
			'message' => ''
			);		
			$content = array(
				'content' => 'master/supplier/view'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }
	
	function editSupplier()
	{
		$kdsupp = $this->uri->segment(3); 
		$dataprofile = array(
			'page_title' => 'Master > Edit Supplier',
			'name' => $this->session->userdata('fullname'),
			'mastersupp' => $this->mastersupplier_model->getSupplierByKode($kdsupp)			
			);		
			$content = array(
				'content' => 'master/supplier/edit'
			);
			$this->template->load('templates/default',$content,$dataprofile);
	}
	
    function ubahmastersupplier() 
	{
        if (isset($_POST['btnSave'])) 
		{
			$this->mastersupplier_model->setKodeSupplier($_POST['kdsupp']);
            $this->mastersupplier_model->setSuppliername($_POST['nmsupp']);
			$this->mastersupplier_model->setAddress($_POST['alamat']);
			$this->mastersupplier_model->setNoTlp($_POST['notlp']);
			$this->mastersupplier_model->setEmail($_POST['email']);
			$this->mastersupplier_model->setNoHp($_POST['nohp']);
            $this->mastersupplier_model->setWebsitename($_POST['nmaweb']);
			$this->mastersupplier_model->setContactPerson($_POST['contact']);
 			$this->mastersupplier_model->setLastUpdateBy($this->session->userdata('userid'));
			$tanggal=date('Y-m-d H:i:s', strtotime('now'));
			$this->mastersupplier_model->setLastUpdateOn($tanggal);
			
            $this->mastersupplier_model->ubahmastersupplier();

            redirect('mastersuppliercontroller');
        } else {
            $this->mastersupplier_model->setKodeSupplier($kdsupp);
            $dataprofile = array(
			'page_title' => 'Master > Supplier',
			'name' => $this->session->userdata('fullname'),
			'mastersupp' => $this->mastersupplier_model->getkdbank()			
			);		
			$content = array(
				'content' => 'master/supplier/edit'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }

    function deletemastersupplier() {
        $kdsupp = $this->uri->segment(3);
        $this->mastersupplier_model->setKodeSupplier($kdsupp);
        $this->mastersupplier_model->deletemastersupp();
        redirect('mastersuppliercontroller');
    }
}